/**
 * Copyright (c) 2007,中企动力华南研发中心<br>
 * All rights reserved.
 */
package com.ce.pms.charge.web;

import java.util.List;

import com.ce.pms.base.web.PmsBaseAction;
import com.ce.pms.charge.model.PeriodDomain;
import com.ce.pms.charge.service.IArCalculateService;
import com.ce.pms.charge.service.IArRecalculateService;
import com.ce.pms.charge.service.IChargeItemService;
import com.ce.pms.charge.service.IPeriodService;
import com.ce.pms.charge.vo.ArCalculateVO;
import com.ce.pms.charge.vo.ChargeItemVO;
import com.ce.pms.charge.vo.PeriodVO;
import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.house.service.IBuildingService;
import com.ce.pms.house.service.IHouseService;
import com.ce.pms.house.vo.BuildingVO;
import com.sitechasia.webx.core.annotation.Read;
import com.sitechasia.webx.core.support.Page;

/**
 * 功能描述：应收计算ACTION<br>
 * @author 罗军林 创建日期：2008-9-9
 */
public class ArCalculateAction extends PmsBaseAction{
	IBuildingService buildingService;
	IChargeItemService chargeItemService;
	IPeriodService periodService;
	IArCalculateService arCalculateService;
	IArRecalculateService arRecalculateService;
	IHouseService houseService;


	public void initMain(){
		List<BuildingVO> buildingList= buildingService.getAllBuildingList();
		List<ChargeItemVO> chargeItemList=chargeItemService.queryChargeItemList(null, false);
		List<PeriodVO> periodList= periodService.findPeriodByValidity(SysrefcodeDO.FEE_PERIOD_VALIDITY_VALID);

		setAttribute("periodList", periodList);
		setAttribute("chargeItemList", chargeItemList);
		setAttribute("buildingList", buildingList);
	}

	public void initGeneralList(){
		setAttribute("totalRows", Integer.valueOf(0));
	}

	public void queryGeneralList(	@Read(key = "ec_crd",defaultValue="15") int pageSize,
									@Read(key = "ec_p",defaultValue="1")	int pageNo,
									@Read ArCalculateVO searchCondition){
		searchCondition.setPageNo(pageNo);
		searchCondition.setPageSize(pageSize);
		Page page=arCalculateService.queryGeneralTran(searchCondition);
		setAttribute("arCalculateList", page.getResult());
		setAttribute("totalRows", new Integer((int) page.getTotalCount()));

	}

	public void initMeterList(){
		setAttribute("totalRows", Integer.valueOf(0));
	}


	public void queryMeterList(	@Read(key = "ec_crd",defaultValue="15") int pageSize,
								@Read(key = "ec_p",defaultValue="1")	int pageNo,
								@Read ArCalculateVO searchCondition){
		searchCondition.setPageNo(pageNo);
		searchCondition.setPageSize(pageSize);
		Page page=arCalculateService.queryMeterTran(searchCondition);
		setAttribute("arCalculateList", page.getResult());
		setAttribute("totalRows", new Integer((int) page.getTotalCount()));

	}

	public void initOtherList(){
		setAttribute("totalRows", Integer.valueOf(0));
	}

	public void queryOtherList(	@Read(key = "ec_crd",defaultValue="15") int pageSize,
								@Read(key = "ec_p",defaultValue="1")	int pageNo,
								@Read ArCalculateVO searchCondition){
		searchCondition.setPageNo(pageNo);
		searchCondition.setPageSize(pageSize);
		Page page=arCalculateService.queryOtherTran(searchCondition);
		setAttribute("arCalculateList", page.getResult());
		setAttribute("totalRows", new Integer((int) page.getTotalCount()));

	}

	public void initChargeTotalList(){
		setAttribute("totalRows", Integer.valueOf(0));
	}

	public void queryChargeTotalList(	@Read(key = "ec_crd",defaultValue="15") int pageSize,
										@Read(key = "ec_p",defaultValue="1")	int pageNo,
										@Read ArCalculateVO searchCondition){
		searchCondition.setPageNo(pageNo);
		searchCondition.setPageSize(pageSize);
		Page page=arCalculateService.queryChargeTotalList(searchCondition);
		setAttribute("arCalculateList", page.getResult());
		setAttribute("totalRows", new Integer((int) page.getTotalCount()));
	}

	public void initCalculate(){

	}

	public void calculate(){
		arCalculateService.calculate(this.getUserId());
		renderText("ok");
	}

	/**
	 * 功能描述:初始化重算界面<br>
	 * <br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-9<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void initRecalculation(@Read (key="houseId")String houseIds,
									@Read (key="houseNumber")String houseNumber){
		PeriodVO periodVO=periodService.queryCurrentPeriod();
		setAttribute("period", periodVO);
		setAttribute("houseId", houseIds);
		setAttribute("houseNumber", houseNumber);
	}

	/**
	 * 功能描述:重算<br>
	 * <br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-9<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void recalculation(@Read (key="periodId") Long periodId,
								@Read (key="houseIds")String houseIds,
								@Read (key="charType")String charType){
		try {
			arRecalculateService.reCalculate(this.getUserId(), periodId, houseIds, charType);
		} catch(org.springframework.dao.DataIntegrityViolationException hibernateConstraintE){
			throw new BusinessException("charge:charge_account_exist_subsidiary_trans_exception",
							BusinessException.ERROR);
		} catch (BusinessException be) {
			throw be;
		}

		renderText("ok");
	}

	public void setBuildingService(IBuildingService buildingService) {
		this.buildingService = buildingService;
	}

	public void setChargeItemService(IChargeItemService chargeItemService) {
		this.chargeItemService = chargeItemService;
	}

	public void setPeriodService(IPeriodService periodService) {
		this.periodService = periodService;
	}

	public void setArCalculateService(IArCalculateService arCalculateService) {
		this.arCalculateService = arCalculateService;
	}

	public void setArRecalculateService(IArRecalculateService arRecalculateService) {
		this.arRecalculateService = arRecalculateService;
	}


}
